package com.qidian.mes.produce.controller;

import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Process;
import com.qidian.mes.produce.service.ProcessService;
import com.qidian.mes.produce.util.IDGenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/16 17:08
 */
@RestController
@RequestMapping("/process")
@CrossOrigin
public class ProcessController {
    @Autowired
    ProcessService processService;

    @Autowired
    private IDGenUtil idGenUtil;

    @GetMapping("/list")
    public MESResult listAll(Process process, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        System.out.println("wqeqweqweqweqweqweqweqweqqqqqqqqqqqqqqqqqqqqqqqqq");
        return processService.queryAll(process,page,limit);

    }

    @PostMapping("/add")
    public MESResult addProcess(@RequestBody Process process){
        System.out.println("sdadwadsadwadsa"+process);
        return processService.addProcess(process);
    }

    @GetMapping("/getRd")
    public MESResult getRandom(){

        return MESResult.success(idGenUtil.genIfId());
    }

    @PutMapping("/modifyProcess")
    public MESResult modifyProcess(@RequestBody Process process){
        System.out.println("wwwwww"+process);
        return processService.modify(process);

    }

    @GetMapping("/getMP")
    public MESResult getModifyProcess(int processRelId){

        return processService.queryById(processRelId);
    }

    @DeleteMapping("/delete")
    public MESResult deleteProcess(int processRelId){
        return processService.delete(processRelId);
    }

    @PostMapping("/deleteAll")
    public MESResult deleteAll(@RequestBody Process[] processes){
         return processService.deleteAll(processes);
    }

    @GetMapping("/nameList")
    public MESResult queryNameList(){
        return processService.queryProcessName();
    }
}
